import junit.framework.Assert;
import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.ActivityTestCase;
import com.jayway.android.robotium.solo.Solo;

import cs2340.spring13.team3.wheresmystuff.presenters.LoginManager;
import cs2340.spring13.team3.wheresmystuff.views.LoginActivity;
import cs2340.spring13.team3.wheresmystuff.views.ViewItemListActivity;


public class ViewItemListActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {

	private Solo solo;
	private LoginManager mLoginManager;
	private Activity mActivity;
	private final String INVALID_EMAIL_ERR = "Invalid email";
	private final String INVALID_PASS_ERR = "Password too short";
	private final String EMPTY_FIELD_ERR = "Field is required";
	
	public ViewItemListActivityTest() {
		super(LoginActivity.class);

	}
	
	@Override
	public void setUp() throws Exception {
		//setUp() is run before a test case is started. 
		//This is where the solo object is created.
		solo = new Solo(getInstrumentation(), getActivity());
	}

	@Override
	public void tearDown() throws Exception {
		//tearDown() is run after a test case has finished. 
		//finishOpenedActivities() will finish all the activities that have been opened during the test execution.
		solo.finishOpenedActivities();
	}
	
	
	public void testSearchEmptyName() throws Exception {
		solo.enterText(0, "t@t.net");
		solo.enterText(1, "password");
		solo.clickOnButton("Login");
		solo.waitForActivity("ViewItemListActivity", 10000);
		solo.assertCurrentActivity("Expected ViewItemListActivity", "ViewItemListActivity");
		solo.clickOnActionBarItem(2131230779);
		solo.waitForDialogToOpen(3000);
		solo.typeText(1, "pet");
		solo.clickOnText("Search");
		solo.waitForDialogToClose(10000);
		Activity a = solo.getCurrentActivity();
		Assert.assertTrue(a instanceof ViewItemListActivity);
		Assert.assertFalse((((ViewItemListActivity)(a)).isListEmpty()));
	}
	
	public void testSearchEmptyTag() throws Exception {
		solo.enterText(0, "t@t.net");
		solo.enterText(1, "password");
		solo.clickOnButton("Login");
		solo.waitForActivity("ViewItemListActivity", 10000);
		solo.assertCurrentActivity("Expected ViewItemListActivity", "ViewItemListActivity");
		solo.clickOnActionBarItem(2131230779);
		solo.waitForDialogToOpen(3000);
		solo.typeText(0, "A lost item");
		solo.clickOnText("Search");
		solo.waitForDialogToClose(10000);
		Activity a = solo.getCurrentActivity();
		Assert.assertTrue(a instanceof ViewItemListActivity);
		Assert.assertFalse((((ViewItemListActivity)(a)).isListEmpty()));
	}
	
	public void testSearchNameAndTag() throws Exception {
		solo.enterText(0, "t@t.net");
		solo.enterText(1, "password");
		solo.clickOnButton("Login");
		solo.waitForActivity("ViewItemListActivity", 10000);
		solo.assertCurrentActivity("Expected ViewItemListActivity", "ViewItemListActivity");
		solo.clickOnActionBarItem(2131230779);
		solo.waitForDialogToOpen(3000);
		solo.typeText(0, "Dog");
		solo.typeText(1, "pet");
		solo.clickOnText("Search");
		solo.waitForDialogToClose(10000);
		Activity a = solo.getCurrentActivity();
		Assert.assertTrue(a instanceof ViewItemListActivity);
		Assert.assertFalse((((ViewItemListActivity)(a)).isListEmpty()));
	}
	
	
	
	
}
